#!/bin/bash
#information
#author: gr.cn 
#email: 920098699@qq.com
#date: Mon Jun  3 19:16:20 CST 2013
#function: restore the file in the File_to_Backup

DATE=`date +%y%m%d`
FILE=archive$DATE.tar.gz
CONFIG_FILE=/home/gr/archive/config/File_to_Backup
DESTINATION=/home/gr/archive/daily/$FILE
########################### Main Script ##########################
#检测配置文件是否存在
if [ ! -f $CONFIG_FILE ]
then
	echo "$CONFIG_FILE doesn't exist"
	echo "Backup can't be completed  due to the loss of config file"
	echo 
	exit 1
fi


#备份文件在配置文件中的行号
FILE_NO=1
#输入重定向
exec < $CONFIG_FILE
read FILE_NAME
while [ $? -eq 0 ]
do
	if [ -f $FILE_NAME -o -d $FILE_NAME ]
	then
		FILE_LIST="$FILE_LIST $FILE_NAME"
	else
		echo "warnings: $FILE_NAME doesn't exist"
		echo "warnings: it's list on line $FILE_NO of the config file"
		echo "warnings: continuing to build archive list..."
		echo
	fi
	FILE_NO=$[$FILE_NO + 1]
	read FILE_NAME
done
#进行备份
tar -czf $DESTINATION $FILE_LIST 2> /dev/null

echo "build archive successfully."
exit 0

